var express = require('express');
var router = express.Router();

router.get('/index', function(req, res, next) {
  // if(req.cookies.login){
  //   res.render('index');
  // }else{
  //   res.redirect("/login");
  // }
  if(req.signedCookies.login){
    res.render('index');
  }else{
    res.redirect("/login");
  }
});
router.get('/login', function(req, res, next) {
  res.render('login');
});
router.post('/check',function(req, res){
  let body=req.body;
  if(body.user==="admin"&&body.password==="123456"){
    res.cookie("login","yes",{maxAge:1000*60*60*24,signed:true});
    res.json({
      msg:"登录成功",
      code:10000
    })
  }else{
    res.json({
      msg:"登录失败",
      code:10005
    })
  }
})

module.exports = router;
